{extend name="adminblue/base" /}
{block name="resources"/}

{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt>默认商品图片：</dt>
		<dd>
			<div class="class-logo">
				<p>
					{if condition="$info.value.default_goods_img"}
					<img id="imgdefault_goods_img" src="{:__IMG($info.value.default_goods_img)}">
					{else/}
					<img id="imgdefault_goods_img">
					{/if}
				</p>
			</div>
			<div class="upload-btn">
				<span>
					<input class="input-file" name="file_upload" id="uploadImgdefault_goods_img" type="file" onchange="imgUpload(this,'default_goods_img');">
					<input type="hidden" id="default_goods_img" value="{$info.value.default_goods_img}" />
				</span>
				<p><i class="fa fa-cloud-upload"></i>上传图片</p>
			</div>
			<p class="hint">
				<br><span style="color: #666;">建议使用宽360像素-高360像素内的JPG或PNG正方形图片；点击下方"提交"按钮后生效。</span>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>默认会员头像：</dt>
		<dd>
			<div class="class-logo">
				<p>
					{if condition="$info.value.default_headimg"}
					<img id="imgdefault_headimg" src="{:__IMG($info.value.default_headimg)}">
					{else/}
					<img id="imgdefault_headimg">
					{/if}
				</p>
			</div>
			<div class="upload-btn">
				<span>
					<input class="input-file" name="file_upload" id="uploadImgdefault_headimg" type="file" onchange="imgUpload(this,'default_headimg');">
					<input type="hidden" id="default_headimg" value="{$info.value.default_headimg}" />
				</span>
				<p><i class="fa fa-cloud-upload"></i>上传图片</p>
			</div>
			<p class="hint">
				<br><span style="color: #666;">建议使用宽120像素-高120像素内的JPG或PNG正方形图片；点击下方"提交"按钮后生效。</span>
			</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="setDefaultImgAjax();">提交</button></dd>
	</dl>
</div>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
//图片上传
var UPLOAD_WEB_COMMON = '{$Think.const.UPLOAD_WEB_COMMON}';// 
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : UPLOAD_WEB_COMMON};
	var id = $(event).next().attr("id");
	uploadFile(fileid,data,function(res){
		if(res.code){
			$("#img"+id).attr("src",__IMG(res.data));
			$("#"+id).val(res.data);
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}

function setDefaultImgAjax(){
	var default_goods_img = $("#default_goods_img").val();
	var default_headimg = $("#default_headimg").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/setDefaultImgAjax')}",
		data : {
			"default_goods_img" : default_goods_img,
			"default_headimg" : default_headimg
		},
		success : function(data){
			if(data["code"] > 0){
				showMessage("success", "设置成功", window.location.reload());
			}else{
				showMessage("error", data["message"], window.location.reload());
			}
		}
	})
}
</script>
{/block}